from django.shortcuts import render
from django.conf import settings
from django_filters.rest_framework import DjangoFilterBackend, FilterSet

from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework.filters import SearchFilter

import time
from iClouds.Permissions import (
    OR,
    AllPermissions,
    MyPermissions,
    BoxPermissions,
    WeChatPermissions,
    BarPermissions,
)
from iClouds.Authentication import (
    MyJWTAuthentication,
    BoxJWTAuthentication,
    WeChatJWTAuthentication,
    BarJWTAuthentication,
)
from iClouds.apidev import filter_views, has_Reqsn_Post, has_Reqsn_Anyone

from . import tasks as TASKS
from .serializers import *
from .FilterBackends import *

from mysqldb import redis as REDIS

# Create your views here.
"""初始化员工"""
# AllinpayStaffList.objects.update_or_create(
#     defaults={"basename": "默认员工", "status": 0}, id=1000
# )


class GetFilterBackend(DjangoFilterBackend):
    """自己定义过滤器"""

    def get_schema_fields(self, view):
        if view.action not in ["list", "retrieve"]:
            return []
        return super().get_schema_fields(view)


# class AllinpayStaffRegisterViewSet(viewsets.ModelViewSet):
#     __title__ = "员工注册"
#     __group__ = "员工模块"
#     __info__ = {"post": "员工注册"}
#     __doc__ = """
#     create:\n
#     <h4>员工注册</h4>\n
#     """
#     http_method_names = ["post"]
#     authentication_classes = []
#     permission_classes = [AllPermissions]
#     serializer_class = AllinpayStaffRegisterSerializer
#     queryset = None

#     def create(self, request, *args, **kwargs):
#         serializer = self.get_serializer(data=request.data)
#         serializer.is_valid(raise_exception=True)
#         # 获取数据
#         username = serializer.data["phone"]
#         sems = serializer.data["password"]
#         # 验证短信
#         if not settings.DEBUG:
#             code = REDIS.redis_get("sems", username, "code")
#             if not code or not sems == code:
#                 raise serializers.ValidationError({"password": "验证码不能匹配"})
#         # 清除短信缓存
#         REDIS.redis_del("sems", username)
#         # 创建数据
#         sess = AllinpayStaffList(phone=username, created=timezone.now(), status=1)
#         sess.save()
#         # 序列化数据
#         r = AllinpayStaffListSerializer(sess)
#         return Response({"rescode": 200, "resmsg": r.data})


class AllinpayStaffListViewSet(viewsets.ModelViewSet):
    __title__ = "员工信息"
    __group__ = "员工模块"
    __info__ = {"get": "查询员工列表或详情", "patch": "编辑员工信息"}
    __doc__ = """
    list:\n
    <h4>员工信息列表</h4>
    retrieve:\n
    <h4>员工信息详情</h4>
    partial_update:\n
    <h4>员工信息编辑</h4>
    """
    http_method_names = ["get", "patch"]
    authentication_classes = [
        MyJWTAuthentication,
        BarJWTAuthentication,
        WeChatJWTAuthentication,
    ]
    permission_classes = [MyPermissions | BarPermissions | WeChatPermissions]
    serializer_class = AllinpayStaffListSerializer
    queryset = AllinpayStaffList.objects.all()

    filter_backends = [ListDjangoFilterBackend, SearchFilter]
    filterset_fields = ["status"]
    search_fields = ["phone", "idcode", "basename"]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def partial_update(self, request, *args, **kwargs):
        if request.data.get("status"):
            raise serializers.ValidationError({"status": "禁止编辑该字段"})
        if request.data.get("created"):
            raise serializers.ValidationError({"created": "禁止编辑该字段"})
        if request.data.get("modifed"):
            raise serializers.ValidationError({"modifed": "禁止编辑该字段"})
        # 是否验证参数完整性 False:验证， True:不验证
        partial = True
        instance = self.get_object()
        instance.modifed = timezone.now()  # 编辑时间
        serializer = self.get_serializer(instance, data=request.data, partial=partial)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response({"rescode": 200, "resmsg": serializer.data})


class AllinpayPlaceinterListViewSet(viewsets.ModelViewSet):
    __title__ = "员工积分列表"
    __group__ = "员工模块"
    __info__ = {"get": "查询员工积分列表或详情"}
    __doc__ = """
    list:\n
    <h4>员工积分列表</h4>
    retrieve:\n
    <h4>员工积分详情</h4>
        <id> 记录id
    """
    http_method_names = ["get"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
    ]
    permission_classes = [MyPermissions | BoxPermissions | WeChatPermissions]
    serializer_class = AllinpayPlaceinterListSerializer
    queryset = AllinpayPlaceinterList.objects.all()

    filter_backends = [ListDjangoFilterBackend]
    filterset_class = AllinpayPlaceinterListFilterSet

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})


class AllinpayPlaceinterLogViewSet(viewsets.ModelViewSet):
    __title__ = "员工积分日志"
    __group__ = "员工模块"
    __info__ = {"get": "查询员工积分日志列表或详情"}
    __doc__ = """
    list:\n
    <h4>员工积分日志列表</h4>
        status:
            0 默认
            1 发起兑换
            2 确认兑换
    retrieve:\n
    <h4>员工积分日志详情</h4>
    """
    http_method_names = ["get"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
    ]
    permission_classes = [MyPermissions | BoxPermissions | WeChatPermissions]
    serializer_class = AllinpayPlaceinterLogSerializer
    queryset = AllinpayPlaceinterLog.objects.all()

    filter_backends = [ListDjangoFilterBackend, SearchFilter]
    filterset_class = AllinpayPlaceinterLogFilterSet
    search_fields = ["reqsn", "post"]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})


class AllinpayInterConvertViewSet(viewsets.ModelViewSet):
    __title__ = "员工积分兑换"
    __group__ = "员工模块"
    __info__ = {"post": "员工积分兑换"}
    __doc__ = """
    create:\n
    <h4>员工积分兑换</h4>
    """
    http_method_names = ["post"]
    authentication_classes = [MyJWTAuthentication, BoxJWTAuthentication]
    permission_classes = [MyPermissions | BoxPermissions]
    serializer_class = AllinpayInterConvertSerializer
    queryset = None

    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        # 测试自动工作
        # try:
        #     r = TASKS.ConvertInterAuto()
        # except BaseException as err:
        #     raise serializers.ValidationError({"err": err})
        # else:
        #     return Response({"rescode": 200, "resmsg": r})

        # 手动工作
        data = serializer.data.copy()
        if not data.get("sid"):
            raise serializers.ValidationError({"sid": "员工异常或已离职"})
        if not data.get("pid"):
            raise serializers.ValidationError({"pid": "场所异常或已离职"})
        if not settings.DEBUG and not data.get("sid") == request.user.id:
            raise serializers.ValidationError({"sid": "非本人账户"})
        if not data.get("intertype") or data.get("intertype") == 1:
            raise serializers.ValidationError({"intertype": "积分类型异常"})
        try:
            r = TASKS.ConvertInterManual(**data)
        except BaseException as err:
            raise serializers.ValidationError({"err": err})
        else:
            return Response({"rescode": 200, "resmsg": r})


class AllinpayInterConvertV2ViewSet(viewsets.ModelViewSet):
    __title__ = "员工积分兑换V2"
    __group__ = "员工模块"
    __info__ = {"get": "查询员工积分兑换单", "post": "创建员工积分兑换单"}
    __doc__ = """
    list:
    <h4>员工积分兑换单列表</h4>
        0 默认
        1 已确认
    retrieve:
    <h4>员工积分兑换单详情</h4>
    create:
    <h4>员工积分兑换单创建</h4>
    """
    http_method_names = ["get", "post"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
    ]
    permission_classes = [MyPermissions | BoxPermissions | WeChatPermissions]
    serializer_class = AllinpayPlaceinterNoneSerializer
    queryset = AllinpayPlaceinterPost.objects.all()

    filter_backends = [ListDjangoFilterBackend, SearchFilter]
    filterset_fields = ["pid", "sid", "intertype", "answer", "status"]
    search_fields = ["reqsn"]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = AllinpayPlaceinterPostSerializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = AllinpayPlaceinterPostSerializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def create(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        # serializer.save()
        print(serializer.data)
        # 计算积分
        count = 0
        for i in serializer.data.get("data"):
            try:
                r = AllinpayPlaceinterLog.objects.get(id=i, status=0)
            except BaseException as err:
                raise serializers.ValidationError({"data": f"积分数据异常 {i}"})
            else:
                if not r.pid == serializer.data.get("pid"):
                    raise serializers.ValidationError({"i": "场所异常"})
                if not r.sid == serializer.data.get("sid"):
                    raise serializers.ValidationError({"i": "员工异常"})
                if not r.intertype == serializer.data.get("intertype"):
                    raise serializers.ValidationError({"i": "积分类型异常"})
                count += r.inter
        print("积分数量:", count)
        # 取汇率
        try:
            conf = AllinpayPlaceinterConf.objects.get(
                pid=serializer.data.get("pid"),
                intetype=serializer.data.get("intertype"),
            )
        except BaseException as err:
            raise serializers.ValidationError({"conf": "积分兑换比例异常"})
        # 最小兑换积分
        if count < conf.mixamount:
            raise serializers.ValidationError({"mixamount": "积分不足"})
        # 取兑换频率
        rate = self.hasData(conf.rate)
        if not rate:
            raise serializers.ValidationError({"rate": "读取兑换频率异常"})
        if rate["name"] == "日":
            l = AllinpayPlaceinterPost.objects.filter(
                pid=serializer.data.get("pid"),
                sid=serializer.data.get("sid"),
                intertype=serializer.data.get("intertype"),
                curentime__year=time.strftime("%Y", time.localtime()),
                curentime__month=time.strftime("%m", time.localtime()),
                curentime__day=time.strftime("%d", time.localtime()),
            ).count()
        elif rate["name"] == "周":
            from datetime import timedelta, date

            t = date.today()
            w = t - timedelta(days=7)
            l = AllinpayPlaceinterPost.objects.filter(
                pid=serializer.data.get("pid"),
                sid=serializer.data.get("sid"),
                intertype=serializer.data.get("intertype"),
                curentime__range=(w, t),
            ).count()
        elif rate["name"] == "月":
            l = AllinpayPlaceinterPost.objects.filter(
                pid=serializer.data.get("pid"),
                sid=serializer.data.get("sid"),
                intertype=serializer.data.get("intertype"),
                curentime__year=time.strftime("%Y", time.localtime()),
                curentime__month=time.strftime("%m", time.localtime()),
            ).count()
        elif rate["name"] == "年":
            l = AllinpayPlaceinterPost.objects.filter(
                pid=serializer.data.get("pid"),
                sid=serializer.data.get("sid"),
                intertype=serializer.data.get("intertype"),
                curentime__year=time.strftime("%Y", time.localtime()),
            ).count()
        else:
            l = 1
        print(l)
        if l > 0:
            raise serializers.ValidationError({"rate": "兑换频率超出限制"})
        answer = 1001 if settings.DEBUG else request.user.id
        # 组织数据
        newdata = {
            "reqsn": has_Reqsn_Post(),
            "pid": serializer.data.get("pid"),
            "sid": serializer.data.get("sid"),
            "answer": answer,
            "intertype": serializer.data.get("intertype"),
            "integral": count,
            "money": count * conf.scale,
            "curentime": timezone.now(),
            "status": 0,
        }
        newLogs = {
            "status": 1,
            "curentimg": newdata["curentime"],
            "post": newdata["reqsn"],
        }
        # 事务处理积分和日志
        from django.db import transaction

        with transaction.atomic():
            # 创建兑换单
            s = AllinpayPlaceinterPostSerializer(data=newdata)
            s.is_valid(raise_exception=True)
            s.save()
            # 修改记录
            AllinpayPlaceinterLog.objects.filter(
                id__in=serializer.data.get("data")
            ).update(**newLogs)
            return Response({"rescode": 200, "resmsg": newdata["reqsn"]})
        return Response({"rescode": 400, "resmsg": "创建失败"})

    def hasData(self, id):
        """取频率"""
        for i in settings.ALL_INTER_CONF:
            if i["id"] == id:
                return i
        return None


class AllinpayInterConvertVVViewSet(viewsets.ModelViewSet):
    __title__ = "兑换单签名"
    __group__ = "员工模块"
    __info__ = {"post": "积分兑换单签名", "put": "签名(停用)"}
    __doc__ = """
    create:
    <h4>积分兑换单签名</h4>
    update:
    <h4>签名(停用)</h4>
    """
    http_method_names = ["post"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
    ]
    permission_classes = [MyPermissions | BoxPermissions | WeChatPermissions]
    serializer_class = ReqsnNoneSerializer
    queryset = AllinpayPlaceinterPost.objects.all()

    def create(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        try:
            instance = AllinpayPlaceinterPost.objects.get(
                reqsn=serializer.data.get("reqsn")
            )
        except BaseException as err:
            raise serializers.ValidationError({"reqsn": "必须本人签收"})
        answer = 1001 if settings.DEBUG else request.user.id
        if not instance.sid == answer:
            raise serializers.ValidationError({"sid": "必须本人签收"})
        instance.modified = timezone.now()  # 编辑时间
        instance.status = 1
        # 事务处理积分和日志
        from django.db import transaction

        with transaction.atomic():
            # 修改单据
            serializer = AllinpayPlaceinterPostSerializer(
                instance, data={"status": 1}, partial=True
            )
            serializer.is_valid(raise_exception=True)
            serializer.save()
            # 修改记录
            AllinpayPlaceinterLog.objects.filter(post=instance.reqsn, status=1).update(
                status=2
            )
            # 转换积分
            try:
                bind = AllinpayPlacestaffList.objects.get(
                    pid=instance.pid, sid=instance.sid
                )
            except BaseException as err:
                raise serializers.ValidationError({"sid": "员工不存在"})
            from .staffSDK import addInter

            x = addInter(
                bind.id,
                instance.intertype,
                -abs(instance.integral),
                "积分兑换出账",
                instance.reqsn,
                2,
            )
            m = addInter(bind.id, 1, instance.money, "积分兑换入账", instance.reqsn, 2)

        return Response({"rescode": 200, "resmsg": serializer.data})


class AllinpayPlaceinterAddsViewSet(viewsets.ModelViewSet):
    __title__ = "员工积分奖励"
    __group__ = "员工模块"
    __info__ = {"get": "查询员工积分奖励", "post": "创建员工积分奖励"}
    __doc__ = """	list:
    <h4>员工积分奖励列表</h4>
    retrieve:
    <h4>员工积分奖励详情</h4>
    create:
    <h4>创建员工积分奖励</h4>
    """
    http_method_names = ["get", "post"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
        BarJWTAuthentication,
    ]
    permission_classes = [
        MyPermissions | BoxPermissions | WeChatPermissions | BarPermissions
    ]
    serializer_class = AllinpayPlaceinterAddsSerializer
    queryset = AllinpayPlaceinterAdds.objects.all()

    filter_backends = [ListDjangoFilterBackend, SearchFilter]
    filterset_fields = ["pid", "sid", "answer", "checker", "intertype", "status"]
    search_fields = ["reqsn"]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def create(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save(
            reqsn=has_Reqsn_Anyone("REWD"),
            status=0,
            answer=request.user.id,
            curentime=timezone.now(),
        )
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})


class AllinpayPlaceinterAddsCheakedViewSet(viewsets.ModelViewSet):
    __title__ = "审核员工积分奖励"
    __group__ = "员工模块"
    __info__ = {"post": "创建审核员工积分奖励"}
    __doc__ = """
    create:
    <h4>创建审核员工积分奖励</h4>
    """
    http_method_names = ["post"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
        BarJWTAuthentication,
    ]
    permission_classes = [
        MyPermissions | BoxPermissions | WeChatPermissions | BarPermissions
    ]
    serializer_class = AllinpayPlaceinterAddsCheakedSerializer
    queryset = AllinpayPlaceinterAdds.objects.all()

    def create(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        try:
            instance = self.get_queryset().get(id=serializer.data.get("ckid"), status=0)
        except BaseException as err:
            raise serializers.ValidationError(f"审核错误,查找对象失败 {err}")
        else:
            instance.status = 1
            instance.checker = request.user.id
            instance.modified = timezone.now()
            instance.save()
            # 计算加分
            res = AllinpayPlaceinterAddsSerializer(instance).data
            TASKS.Production_points.apply_async(
                (res.get('pid'), res.get('sid'), res.get('reqsn'), res.get('intName'), res.get('intertype'), res.get('integral'))
            )

        return Response({"rescode": 200, "resmsg": "OK"})


class AllinpayStaffteamListViewSet(viewsets.ModelViewSet):
    __title__ = "团队列表"
    __group__ = "员工模块"
    __info__ = {"get": "查询团队列表", "post": "创建团队", "put": "编辑团队", "delete": "解散团队"}
    __doc__ = """	list:
    <h4>查询团队列表</h4>
    retrieve:
    <h4>查询团队详情</h4>
    create:
    <h4>创建团队</h4>
    update:
    <h4>编辑团队</h4>
    delete:
    <h4>解散团队</h4>
    """
    http_method_names = ["get", "post", "put", "delete"]
    authentication_classes = (
        []
        if settings.DEBUG
        else [
            MyJWTAuthentication,
            BoxJWTAuthentication,
            WeChatJWTAuthentication,
        ]
    )
    permission_classes = (
        [AllPermissions]
        if settings.DEBUG
        else [MyPermissions | BoxPermissions | WeChatPermissions]
    )
    serializer_class = AllinpayStaffteamListSerializer
    queryset = AllinpayStaffteamList.objects.all()

    filter_backends = [ListDjangoFilterBackend]
    filterset_fields = ["pid", "status"]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def create(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response({"rescode": 200, "resmsg": serializer.data})

    def update(self, request, *args, **kwargs):
        partial = True
        instance = self.get_object()
        serializer = self.get_serializer(instance, data=request.data, partial=partial)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response({"rescode": 200, "resmsg": serializer.data})

    def destroy(self, request, *args, **kwargs):
        instance = self.get_object()
        self.perform_destroy(instance)
        return Response({"rescode": 200, "resmsg": "SUCCESS"})


class GIncentivesConfViewSet(viewsets.ModelViewSet):
    __title__ = "全民激励配置"
    __group__ = "激励模块"
    __info__ = {
        "get": "查询全民激励配置",
        "post": "创建全民激励配置",
        "put": "编辑全民激励配置",
        "delete": "移除全民激励配置",
    }
    __doc__ = """	list:
    <h4>全民激励配置列表</h4>
    retrieve:
    <h4>全民激励配置详情</h4>
    create:
    <h4>创建全民激励配置</h4>
    update:
    <h4>编辑全民激励配置</h4>
    delete:
    <h4>移除全民激励配置</h4>"""
    http_method_names = ["get", "post", "put", "delete"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
    ]
    permission_classes = [MyPermissions | BoxPermissions | WeChatPermissions]
    serializer_class = GIncentivesConfSerializer
    queryset = GIncentivesConf.objects.all()

    filter_backends = [ListDjangoFilterBackend]
    filterset_fields = ["pid", "tid", "sid", "status"]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def create(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response({"rescode": 200, "resmsg": serializer.data})

    def update(self, request, *args, **kwargs):
        partial = True
        print(request.data)
        instance = self.get_object()
        serializer = self.get_serializer(instance, data=request.data, partial=partial)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response({"rescode": 200, "resmsg": serializer.data})

    def destroy(self, request, *args, **kwargs):
        instance = self.get_object()
        self.perform_destroy(instance)
        return Response({"rescode": 200, "resmsg": "SUCCESS"})


class GIncentivesListViewSet(viewsets.ModelViewSet):
    __title__ = "当日激励成就达成阶段"
    __group__ = "激励模块"
    __info__ = {"get": "查询当日激励成就达成阶段"}
    __doc__ = """	
    list:
    <h4>当日激励成就达成阶段列表</h4>
    retrieve:
    <h4>当日激励成就达成阶段详情</h4>
    """
    http_method_names = ["get"]
    authentication_classes = [
        MyJWTAuthentication,
        BoxJWTAuthentication,
        WeChatJWTAuthentication,
    ]
    permission_classes = [MyPermissions | BoxPermissions | WeChatPermissions]
    serializer_class = GIncentivesListSerializer
    queryset = GIncentivesList.objects.all()

    filter_backends = [ListDjangoFilterBackend]
    filterset_fields = ["pid", "tid", "sid", "status", "nowdate"]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return Response({"rescode": 200, "resmsg": serializer.data})

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serializer(instance)
        return Response({"rescode": 200, "resmsg": serializer.data})


# 检查视图
filter_views(globals())
